package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.model.BaseAttrInfo;
import com.atguigu.gmall.product.model.BaseAttrValue;
import com.atguigu.gmall.product.service.BaseAttrInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author: atguigu
 * @create: 2023-08-28 16:36
 */
@RestController
@RequestMapping("/admin/product")
public class BaseAttrInfoController {

    @Autowired
    private BaseAttrInfoService baseAttrInfoService;

    /**
     * 根据三级分类ID查询包含平台属性列表（包含属性值）
     *
     * @param category1Id
     * @param category2Id
     * @param category3Id
     * @return
     */
    @ApiOperation("根据三级分类ID查询包含平台属性列表（包含属性值）")
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result getAttrInfoList(
            @PathVariable("category1Id") Long category1Id,
            @PathVariable("category2Id") Long category2Id,
            @PathVariable("category3Id") Long category3Id
    ) {
        List<BaseAttrInfo> list = baseAttrInfoService.getAttrInfoList(category1Id, category2Id, category3Id);
        return Result.ok(list);
    }

    /**
     * 平台属性新增或者修改
     * @param baseAttrInfo
     * @return
     */
    @ApiOperation("平台属性新增或者修改")
    @PostMapping("/saveAttrInfo")
    public Result saveorUpdateAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        baseAttrInfoService.saveorUpdateAttrInfo(baseAttrInfo);
        return Result.ok();
    }

    /**
     * 根据平台属性Id 获取到平台属性值集合
     * @param attrId
     * @return
     */
    @ApiOperation("根据平台属性Id 获取到平台属性值集合")
    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable("attrId") Long attrId){
        List<BaseAttrValue> list = baseAttrInfoService.getAttrValueList(attrId);
        return  Result.ok(list);
    }
}
